#!/bin/sh

# M109: Set Extruder Temperature and Wait 
# M109 in Marlin, Sprinter (ATmega port)
# Set extruder heater temperature in degrees celsius and wait for this
# temperature to be achieved.
# Example: M109 S185 

temp_required=$1
temp_actual=$(halcmd getp Therm.temp0)

halcmd sets e0.temp.set $temp_required
#bash cannot do floating point comparison
T_extruder_smaller_than_T_required=`echo "scale=3; ($temp_actual < $temp_required)"| bc -l`
#echo "Ta<Tr? $T_extruder_smaller_than_T_required"
while [ "$T_extruder_smaller_than_T_required" != "0" ]
do
#  echo enter while loop
  temp_actual=$(halcmd getp Therm.temp0)
#  echo temp_actual= $temp_actual
  sleep 1
  T_extruder_smaller_than_T_required=`echo "scale=3; ($temp_actual < $temp_required)"| bc -l`
#  echo "Ta<Tr? $T_extruder_smaller_than_T_required"
done
#echo temp reached
exit 0

